package com.ck.print.demo.printbridge.message.handler.center;

import com.ck.print.demo.printbridge.MacAddressUtil;
import com.ck.print.demo.printbridge.PrintWebSocketClient;
import com.ck.print.demo.printbridge.message.handler.AMessageHandle;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

public class QueryAgentMacHandle extends AMessageHandle {
    private static final String Query_Agent_Mac = "agent.queryAgentMac";

    public QueryAgentMacHandle(String clientInfo) {
        super(clientInfo);
    }

    @Override
    public Boolean apply(Map<String, Object> dataMap, PrintWebSocketClient currentClient, PrintWebSocketClient friendClient) {
        if (dataMap.containsKey("call")) {
            String clientMethod = (String) dataMap.get("call");

            // 处理打印中心发送的mac地址查询请求
            if (StringUtils.equalsIgnoreCase(Query_Agent_Mac, clientMethod)) {
                Map<String, String> data = new HashMap<>();
                data.put(Query_Agent_Mac, MacAddressUtil.agentMac());
                currentClient.send(gson.toJson(data));
                return true;
            }
        }
        return false;
    }
}
